//package com.example.utils.config;
//
//
//
//import org.apache.catalina.security.SecurityUtil;
//import org.apache.shiro.SecurityUtils;
//import org.apache.shiro.authc.AuthenticationException;
//import org.apache.shiro.authc.AuthenticationInfo;
//import org.apache.shiro.authc.AuthenticationToken;
//import org.apache.shiro.authc.SimpleAuthenticationInfo;
//import org.apache.shiro.authc.UsernamePasswordToken;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.realm.AuthorizingRealm;
//import org.apache.shiro.subject.PrincipalCollection;
//import org.apache.shiro.subject.Subject;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import com.example.domain.User;
//import com.example.service.UserService;
//
////自定义的UserRealm extends AuthorizingRealm
//public class UserRealm extends AuthorizingRealm{
//	
//	@Autowired
//	UserService userService;
//	
//	//授权
//	@Override
//	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//		
//		System.out.println("执行了=>授权doGetAuthorizationInfo");
//		return null;
//	}
//	
//	//认证
//	@Override
//	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
//
//		System.out.println("执行了=>认证doGetAuthenticationInfo");
//		
//		//用户名, 密码~ 数据中取
//		
////		String name = "admin";
////		
////		String password = "123456"; 
//		
//		UsernamePasswordToken userToken = (UsernamePasswordToken)token;
//		
////		if(!userToken.getUsername().equals(name)) {
////			return null; //抛出异常 UnknownAccountException
////		}
//		// 获取用户名
//		User user = userService.findByName(userToken.getUsername());
//		if(user == null) { //没有这个人
//			return null; //UnknownAccountException 
//		}
//		//密码认证,shiro做~
//		
//		return new SimpleAuthenticationInfo("",user.getPassword(),"");
//	}
//
//	
//}
